package com.foreverwin.mes.meapi.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.foreverwin.mes.core.base.FrontPage;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.foreverwin.mes.meapi.model.BomComponent;
import com.foreverwin.mes.meapi.mapper.BomComponentMapper;
import com.foreverwin.mes.meapi.service.BomComponentService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Locale;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ervin Chen
 * @since 2020-02-07
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BomComponentServiceImpl extends ServiceImpl<BomComponentMapper, BomComponent> implements BomComponentService {


    @Autowired
    private BomComponentMapper bomComponentMapper;

    @Override
    public Page<BomComponent> selectPage(FrontPage<BomComponent> frontPage, BomComponent bomComponent) {
        EntityWrapper<BomComponent> queryWrapper = new EntityWrapper<>();
        queryWrapper.setEntity(bomComponent);
        return super.selectPage(frontPage.getPagePlus(), queryWrapper);
    }

    @Override
    public List<BomComponent> selectList(BomComponent bomComponent) {
        EntityWrapper<BomComponent> queryWrapper = new EntityWrapper<>();
        queryWrapper.setEntity(bomComponent);
        return super.selectList(queryWrapper);
    }

    @Override
    public List<BomComponent> selectBomComponentByOperation(Wrapper<BomComponent> wrapper, String operationBo) {
        return bomComponentMapper.selectBomComponentByOperation( wrapper, operationBo );
    }

    @Override
    public List<BomComponent> listByBomBo(String bomBo) {
        Locale locale = LocaleContextHolder.getLocale();
        return bomComponentMapper.selectByBomBo(locale.getLanguage(), bomBo);
    }
}